import Vue from 'vue'
// 导入路由
import VueRouter from 'vue-router'
import login from '@/views/login/index.vue'
import test from '@/views/test/index.vue'
import index from '@/views/index/index.vue'
// 引入index的嵌套路由
import chart from '../views/index/chart/index.vue'
import user from '../views/index/user/index.vue'
import question from '../views/index/question/index.vue'
import company from '../views/index/company/index.vue'
import subject from '../views/index/subject/index.vue'
import notFound from '../views/notFound/index.vue'

// 初始化路由
Vue.use(VueRouter)

// 配置路由规则
const routes = [
  // 登录页面路由
  {
    path: '/login',
    component: login,
    meta: {
      title: '登录'
    }
  },
  // 默认重定向到登录页面
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/index',
    component: index,
    redirect: '/index/chart',
    children: [
      {
        path: 'chart',
        component: chart,
        meta: {
          title: '数据概览'
        }
      },
      {
        path: 'user',
        component: user,
        meta: {
          title: '用户列表'
        }
      },
      {
        path: 'question',
        component: question,
        meta: {
          title: '题库列表'
        }
      },
      {
        path: 'company',
        component: company,
        meta: {
          title: '企业列表'
        }
      },
      {
        path: 'subject',
        component: subject,
        meta: {
          title: '学科列表'
        }
      }
    ]
  },
  {
    path: '/test',
    component: test
  },
  // 404路由
  {
    path: '*',
    component: notFound,
    meta: {
      title: 'notFound'
    }
  }
]

// 设置路由
const router = new VueRouter({
  routes
})

// 设置全局后置守卫
router.afterEach((to, from) => {
  document.title = to.meta.title
})

// 将配置好的路由暴露出去
export default router
